package security;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class PassToMD5 {

	private static String blowfish = "kQI8u5uz6)RE*4JluuQx=cPIHo}lwi35o]~]*X";

	public static String crypt(String password) throws NoSuchAlgorithmException {
		password += blowfish;
		byte[] uniqueKey = password.getBytes();
		byte[] hash = null;
		hash = MessageDigest.getInstance("MD5").digest(uniqueKey);
		StringBuilder hashString = new StringBuilder();
		for (int i = 0; i < hash.length; i++) {
			String hex = Integer.toHexString(hash[i]);
			if (hex.length() == 1) {
				hashString.append('0');
				hashString.append(hex.charAt(hex.length() - 1));
			} else
				hashString.append(hex.substring(hex.length() - 2));
		}
		return hashString.toString();
	}
}
